// 云函数入口文件
const cloud = require('wx-server-sdk')
const {
  WXMINIUser,
  WXUniformMessage
} = require('wx-js-utils');

const appId = 'wxd6f3643cc7f65066'
const secret = '6a1b838886d1293fbfeb50a32f8451f0'
const template = 'Gk0ZjtNROyIpH6yyIKaqcG12vHzmRVhM6_sXq_P15MM'

cloud.init()
const db = cloud.database();
// 云函数入口函数
exports.main = async (event, context) => {
  let wXMINIUser = new WXMINIUser({
    appId,
    secret
  });
  let access_token = await wXMINIUser.getAccessToken();
  var touser = event.target
  var openid = event.openid
  var name = event.name
  var form_id = event.formid
  let result = await cloud.openapi.subscribeMessage.send({
    touser: openid,
    page: 'pages/index/index',
    data: {
      thing7: event.title,
      thing5: name
    },
    templateId:template
  })
  return result
}